(function() {
    !window.g_imconfig && (window.g_imconfig = {});
    g_imconfig.host || (g_imconfig.host = '<%= host %>');
    g_imconfig.imHost || (g_imconfig.imHost = '<%= imHost %>');
    g_imconfig.mode || (g_imconfig.mode = 2);
    function addJS(url, cb){
        if(typeof require == 'function' && typeof define == 'function' && define.amd){
            require([g_imconfig.host + url+'.js'], function(io){
                if(cb){
                    cb();
                }
                if(io){
                    window.io = io;
                }
            });
            return 0;
        }
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = g_imconfig.host + url + '.js';
        var x = document.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(s, x);
        cb && (s.onload = s.onreadystatechange = (function(){
            if(s&&s.readyState){
                if(s.readyState.match(/loaded|complete/i)){
                    cb();
                }
            }else{
                cb();
            }
        }));
    }
    function addCSS(url){
        var s = document.createElement('link');
        s.type = 'text/css';
        s.rel = 'stylesheet';
        s.href = g_imconfig.host + url;
        var x = document.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(s, x);
    }

    addCSS('/css/index.css');
    addJS('/socket', function(){
        addJS('/client');
    });
})();
